<template>
    <div class="assetmodule-substance">

        <div class="cont-table">
            <Table border stripe :columns="columns1" @on-selection-change="selectOnes" :data="datas" :loading="load"></Table>
        </div>

        <div class="cont-page">
            <Page :total="pageDate.total" :page-size="pageDate.per_page" :current="pageDate.current_page" @on-change="queryDatas" show-total></Page>
        </div>
    </div>
</template>

<script>
export default {
    props: {
        condition: {
            type: [Boolean, Number],
            default: false
        }
    },
    data () {
        return {
            load: true,
            pageDate: {
                total: 0,
                current_page: 1,
                per_page: 0
            },

            datas: [],
            columns1: [
                {
                    type: 'selection',
                    width: 60,
                    align: 'center',
                    fixed:'left'
                },
                {
                    title: '部门',
                    minWidth: 150,
                    align: 'center',
                    render: (h, params) => {
                        if(params.row.department_name){
                            let name=params.row.department_name.zh?params.row.department_name.zh:params.row.department_name.mn
                            return h('div',name )
                        }
                        
                    }
                },
                {
                    title: '岗位',
                    minWidth: 150,
                    align: 'center',
                    render: (h, params) => {
                        let name=params.row.position_name.position_name.zh
                        return h('div',name )
                    }
                },
                {
                    title: '人员',
                    minWidth: 150,
                    align: 'center',
                    render: (h, params) => {
                        if(params.row.teacher_name.length> 0){
                            let name=params.row.teacher_name[0].teacher_name.zh
                            return h('div',name )
                        }
                        
                    }
                },
                {
                    title: '操作',
                    key: 'action',
                    width: 100,
                    align: 'center',
                    fixed:'right',
                    render: (h, params) => {
                        return h('div', [
                            h('Poptip', {
                                props: {
                                    confirm: true,
                                    transfer: true,
                                    title: '您确定要删除这条数据吗?',
                                    type: 'error',
                                    size: 'small',
                                    placement:'left-end'
                                },
                                style: {
                                    textAlign: 'left',
                                },
                                on: {
                                    'on-ok': () => {
                                        this.removes(params.row.id)
                                    }
                                }
                            }, [
                                h('Button', {
                                    directives: [
                                        {
                                            name: 'button',
                                            value: 'del',
                                        }
                                    ],
                                    props: {
                                        type: 'error',
                                        size: 'small'
                                    }
                                }, '删除')
                            ]),
                        ])
                    }
                },
            ],

            selUrl: 'api/watchlist/v1/get/admininspecttermuser/list',
            delUrl: 'api/watchlist/v1/administrativedutyuser/del/',
            
            delVlaue: []
        }
    },
    methods: {
        
        /************************************************************
         * 
         * 批量删除数据
         * @param   {index}            所选数据id[array]
         * 
         ************************************************************/
        selectOnes (index) {
            this.delVlaue = index.map(el => {
                return el.id
            })
            this.$emit('delPush', this.delVlaue)
        },
        
        /************************************************************
         * 
         * 数据              
         * @param   {index}        id
         * 
         ************************************************************/
        removes (index) {
            this.$http.delete(`${this.delUrl}[${index}]`).then(val=>{
                this.datas = []
                this.load = true
                this.queryDatas (this.pageDate.current_page)
            }).catch(err => {
            })
        },
        
        /************************************************************
         * 
         * 数据              
         * @param   {value}         分页
         * 
         ************************************************************/
        queryDatas (index) {
            let params = {
                administrativeduty_id: this.condition,
                page: index
            }
            this.$http.get(this.selUrl, { params }).then(val=>{
                this.pageDate.per_page = val.pages.per_page
                this.pageDate.total = val.pages.total
                this.pageDate.current_page = val.pages.current_page
                this.datas = val.data 
                this.load = false
            }).catch(err => {
                this.load = false
            })
        },
    },
    created () {
        if (this.condition) this.queryDatas (1)
    },
}
</script>
<style lang="less">
.assetmodule-substance{
    width: 100%;
    height: 100%;
    position: relative;
    .cont-table{
        position: absolute;
        left: 0;
        right: 0;
        top: 0;
        bottom: 50px;
        overflow: auto;
    }
    .cont-page{
        height: 43px;
        padding-top: 10px;
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        border-top: 1px solid #dddee1;
    }
}
</style>
